<?php
	include_once '../config.inc.php';
		//如果是未登陆则跳转到登陆页
	if($adminId <= 0 ){
		echo '<script type="text/javascript">location.href = \'login.php\';</script>';
		die(0);
	}
	if(isset($_GET['orderid']) && !empty($_GET['orderid'])){
		$stmt = $pdo->prepare('select * from kp_sell_order where uid = ? and sid=? and zt=1 order by overdate desc');
		$stmt->execute(array($uid,$_GET['orderid']));
		
	}else{
		$stmt = $pdo->prepare('select * from kp_sell_order order by overdate desc');
		$stmt->execute(array($uid));
	}
	$ordersArr = $stmt->fetchAll(PDO::FETCH_ASSOC);
	
	//print_r($goodArr);
?>
<!DOCTYPE html>
<html lang="zh">
	<head>
		<meta charset="UTF-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<meta http-equiv="X-UA-Compatible" content="ie=edge" />
		<link rel="stylesheet" type="text/css" href="css/uorders.css"/>
		<script src="../js/jquery-3.1.1.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/kporder.js" type="text/javascript" charset="utf-8"></script>
		<title>Document</title>
	</head>
	<body>
		<div id="uorder">
			<div class="title">
				后台管理: 订单管理
			</div>
			<?php
				if(!empty($ordersArr)){
					foreach($ordersArr as $order){
						$stmt = $pdo->prepare('select a.sid,a.gid,b.gname,a.num,a.zkprice,a.evaluate from (select * from kp_sell where sid in(select sid from kp_sell_order where uid = ? and sid = ?)) a left join kp_goods b on a.gid = b.gid');
						$stmt->execute(array($uid,$order['sid']));
						$goodArr = $stmt->fetchAll(PDO::FETCH_ASSOC);
						
						//查询出收件人信息与支付方式信息
						$stmtAddress = $pdo->prepare('select uname,address,tel from kp_usr_address where id=?');
						$stmtAddress->execute(array($order['addressid']));
						$addressArr = $stmtAddress->fetch(PDO::FETCH_ASSOC);
						
			?>
			<div class="orders">
				<div class="payinfo">
					<div style="float: left;font-size: 12px; color: #999; height: 23px; line-height: 25px;">单号:</div>
					<h3 class="ssid"><?php echo $order['sid']?></h3>
					<div class="payzt">
						<ul>
							<?php if($order['zt'] == 1){ ?>
							<li class="odel">[删除]</li>
							<li class="oexp">[发货]</li>
							<?php } ?>
							<li class="expid" style="min-width: 100px;" <?php if($order['zt'] == 1) echo 'contenteditable="true"'; ?>><?php  echo $order['expid'];?></li>
							<li><?php if($order['zt'] >= 1) echo '快递:';  ?></li>
							<li><?php if($order['zt'] == 1) echo '待发货'; elseif($order['zt'] == 2) echo '待收货'; elseif($order['zt'] == 3) echo '交易完成';elseif($order['zt'] == 0) echo '已删除';  ?></li>
							<li>订单状态:</li>
						</ul>
					</div>
					<ul>
						<li>支付金额:¥<?php echo $order['zmoney'];?></li>
						<li>收件人信息:<?php echo $addressArr['address'] .' ('.$addressArr['uname'].') '.$addressArr['tel'] ;?></li>
					</ul>
					
				</div>
				<!--订单商品详情-->
				<ul class="goodtitle">
					<li class="c0">编号</li>
					<li class="c1">名称</li>
					<li class="c2">单价</li>
					<li class="c3">数量</li>
					<li class="c4">小计</li>
					<li class="c5">评价</li>
				</ul>
					<?php 
						//$sum = 0.0;
						foreach($goodArr as $good){
						
					?>
					<ul class="good" id="<?php echo 'g_' . $good['gid']; ?>">
					<li class="c0"><?php echo $good['gid']; ?></li>
					<li class="c1"><?php echo $good['gname']; ?></li>
					<li class="c2"><?php echo $good['zkprice']; ?></li>
					<li class="c3"><?php echo $good['num']; ?></li>
					<li class="c4"><?php echo number_format(($good['zkprice']* $good['num']),2,'.','') ?></li>
					<li class="c5" <?php if(empty($good['evaluate'])) echo 'contenteditable="true"'; ?>>
						<?php if(!empty($good['evaluate'])){ 
							
						echo $good['evaluate'];
						?>
							
							<input type="button" class="submit" value="删除" onclick="goEvaluate(<?php echo '\''.$order['sid'].'\',\''.$good['gid'].'\',this'; ?>)" />
						<?php
						 }else{
						 	//echo $good['evaluate'];
						 }
						 ?>
					</li>
				</ul>
				<?php
						//$sum += ($good['zkprice'] * $good['carnum']);
						}
						echo '</div>';
					}
					
				}
				?>
				<!--订单商品详情-->
			<!--</div>-->
		</div>
	</body>
</html>